{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mean(a):\n",
    "    return a.mean()\n",
    "\n",
    "def rms(a):\n",
    "    return np.sqrt(np.square(a).mean())\n",
    "\n",
    "def rmc(a):\n",
    "    return np.cbrt(np.power(a, 3).mean())\n",
    "\n",
    "def compare(a):\n",
    "    a = np.array(a)\n",
    "    print(f'input: {a}')\n",
    "    print(f'Mean: {mean(a)}')\n",
    "    print(f'RMS: {rms(a)}')\n",
    "    print(f'RMC: {rmc(a)}')\n",
    "    print('')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input: [0.2 0.3 0.7]\n",
      "Mean: 0.39999999999999997\n",
      "RMS: 0.4546060565661952\n",
      "RMC: 0.5013297934964582\n",
      "\n",
      "input: [0.1 0.2 0.9]\n",
      "Mean: 0.4000000000000001\n",
      "RMS: 0.5354126134736337\n",
      "RMC: 0.6265826556058272\n",
      "\n",
      "input: [0.4 0.5 0.6]\n",
      "Mean: 0.5\n",
      "RMS: 0.5066228051190221\n",
      "RMC: 0.5129927840030089\n",
      "\n",
      "input: [0.3 0.3 0.8]\n",
      "Mean: 0.4666666666666666\n",
      "RMS: 0.5228129047119374\n",
      "RMC: 0.573541778662744\n",
      "\n",
      "input: [0.1 0.8 0.8]\n",
      "Mean: 0.5666666666666668\n",
      "RMS: 0.6557438524302002\n",
      "RMC: 0.6990917926875482\n",
      "\n"
     ]
    }
   ],
   "source": [
    "compare([0.2, 0.3, 0.7])\n",
    "compare([0.1, 0.2, 0.9])\n",
    "compare([0.4, 0.5, 0.6])\n",
    "compare([0.3, 0.3, 0.8])\n",
    "compare([0.1, 0.8, 0.8])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0.2000, 0.3000, 0.7000],\n",
       "         [0.1000, 0.2000, 0.9000]],\n",
       "\n",
       "        [[0.4000, 0.5000, 0.6000],\n",
       "         [0.3000, 0.3000, 0.8000]]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = torch.tensor([\n",
    "    [\n",
    "        [0.2, 0.3, 0.7],\n",
    "        [0.1, 0.2, 0.9],\n",
    "    ],\n",
    "    [\n",
    "        [0.4, 0.5, 0.6],\n",
    "        [0.3, 0.3, 0.8],\n",
    "    ]\n",
    "])\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0.0400, 0.0900, 0.4900],\n",
       "         [0.0100, 0.0400, 0.8100]],\n",
       "\n",
       "        [[0.1600, 0.2500, 0.3600],\n",
       "         [0.0900, 0.0900, 0.6400]]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tsq = torch.mul(t, t)\n",
    "tsq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0.1000, 0.1700, 0.4250],\n",
       "         [0.0500, 0.0650, 0.7250]]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tm = tsq.mean(dim=0, keepdims=True)\n",
    "tm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0.3162, 0.4123, 0.6519],\n",
       "         [0.2236, 0.2550, 0.8515]]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.sqrt(tm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6694329500821694"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cbrt(0.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(0.6694)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = torch.tensor(0.3)\n",
    "p = torch.tensor(1/3)\n",
    "torch.pow(t, p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
